from rest_framework.authentication import SessionAuthentication
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView
from rest_framework.permissions import IsAuthenticated

from book_drf.serializers import BooksSerialzier
from books.models import BookInfo


class BooksDRF(ListCreateAPIView):#儿子继承三个老把查询和保存
    """
        获取所有图书和保存图书
    """
    serializer_class = BooksSerialzier # 指定当前视图使用那个序列化器
    queryset = BookInfo.objects.all()  # 指定当前视图使用那个查询集数据对象
    authentication_classes = [SessionAuthentication]
    permission_classes = [IsAuthenticated]



class BookDRF(RetrieveUpdateDestroyAPIView):#儿子继承了四个老爸,单一数据查询,修改,删除
    """
        获取单一图书和修改删除
    """
    serializer_class = BooksSerialzier  # 指定当前视图使用那个序列化器
    queryset = BookInfo.objects.all()  # 指定当前视图使用那个查询集数据对象

